//
//  LVImpListCell.m
//  LEVE
//
//  Created by 上官惠阳 on 2017/2/27.
//  Copyright © 2017年 dashuju. All rights reserved.
//

#import "LVImpListCell.h"
#import "UIView+Layer.h"
#import "LVShareCell.h"
#import "LVImpModel.h"

//#define itemWidth ((kScreenWidth == 320) ? 38 : 45)
#define itemWidth 45

@interface LVImpListCell()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>

@end

@implementation LVImpListCell
{
    LVImpModel *_impModel;
}
- (void)awakeFromNib {
    [super awakeFromNib];

    _shareCollectView.delegate = self;
    _shareCollectView.dataSource = self;
    [_shareCollectView registerNib:[UINib nibWithNibName:@"LVShareCell" bundle:nil] forCellWithReuseIdentifier:@"LVShareCell"];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self makeUI];
}
- (void)makeUI
{
    [_headIconImgView layerRoundCorner];
}
- (void)loadCellWithModel:(LVImpModel *)model
{
    _impModel = model;

    CGFloat spa = 10;
    CGFloat cWidth = _impModel.shareModelArr.count * (itemWidth + spa) - spa;
    NSInteger count = (kScreenWidth == 320) ? 2 : 3;
    CGFloat maxCWidth = count * (itemWidth + spa) - spa;
    _collectionWidth.constant = cWidth > maxCWidth ? maxCWidth : cWidth;
    _nameRigth.constant = count * (itemWidth + spa + 5);

    [_shareCollectView reloadData];
}
#pragma mark UICollectionDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  _impModel.shareModelArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LVShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LVShareCell" forIndexPath:indexPath];
    //cell的图片加载
    LVShareModel *sModel = _impModel.shareModelArr[indexPath.row];

    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(itemWidth, itemWidth);
}
#pragma mark UICollectionDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LVShareModel *sModel = _impModel.shareModelArr[indexPath.row];
    if (_seleteShareBlock) {
        _seleteShareBlock(sModel);
    }
}
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end
